package com.myhome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.aspectj.weaver.ast.Var;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.myhome.mapper.NoticeMapper;
import com.myhome.domain.Notice;
import com.myhome.service.NoticeService;
import org.springframework.util.StringUtils;

/**
*@Author QYiXin 
* @Date 2021 10 09 12 58
**/
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService{

    @Override
    public Page<Notice> getPagesNotices(Page<Notice> page, String title, String startTime, String endTime) {
        Page<Notice> resultNotices = this.page(page, new LambdaQueryWrapper<Notice>().like(!StringUtils.isEmpty(title), Notice::getTitle, title)
                .between((!StringUtils.isEmpty(startTime)&&!StringUtils.isEmpty(endTime)),Notice::getCreated, startTime, endTime + " 23:59:59")
        );
        return resultNotices;
    }

    @Override
    public Page<Notice> getAllSimpleNotice(Page<Notice> page) {
        return this.page(page, new LambdaQueryWrapper<Notice>().eq(Notice::getStatus, (byte) 1).orderByAsc(Notice::getSort));
    }
}
